import webchatSchedult from '../../../../api/config/channel/webchat-schedult'
import * as globalTypes from '../../../../mutation-types'

/* 获取所有节点列表 start */
/**
 * 获取所有类型的节点
 * @param {}  传值为空即可
 * @returns {*}
 */
export const getNodeList = ({commit, state, rootState, dispatch}, data) => {
  return webchatSchedult.getNodeList(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}

/* 添加节点 start */
/**
 * 添加在线咨询流程节点
 * @param {}  传值为空即可
 * @returns {*}
 */
export const addNode = ({commit, state, rootState, dispatch}, data) => {
  return webchatSchedult.addNode(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/* 更新节点 start */
/**
 * 更新在线咨询流程节点
 * @param
 * @returns {*}
 */
export const updateNode = ({commit, state, rootState, dispatch}, data) => {
  return webchatSchedult.updateNode(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/* 删除节点 start */
/**
 * 删除在线咨询流程节点
 * @param
 * @returns {*}
 */
export const delNode = ({commit, state, rootState, dispatch}, data) => {
  return webchatSchedult.delNode(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/* 查询节点 start */
/**
 * 添加在线咨询流程节点
 * @param
 * @returns {*}
 */
export const getNodeById = ({commit, state, rootState, dispatch}, data) => {
  return webchatSchedult.getNodeById(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/* 查询流程 start */
/**
 * 查询在线咨询流程
 * @param
 * @returns {*}
 */
export const getProcessList = ({commit, state, rootState, dispatch}, data) => {
  return webchatSchedult.getProcessList(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/* 根据ID查询流程 start */
/**
 * 根据ID查询在线咨询流程
 * @param
 * @returns {*}
 */
export const getProcessById = ({commit, state, rootState, dispatch}, data) => {
  return webchatSchedult.getProcessById(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/* 添加流程 start */
/**
 * 添加在线咨询流程
 * @param
 * @returns {*}
 */
export const addProcess = ({commit, state, rootState, dispatch}, data) => {
  return webchatSchedult.addProcess(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/* 修改流程 start */
/**
 * 修改在线咨询流程节点
 * @param
 * @returns {*}
 */
export const updateProcess = ({commit, state, rootState, dispatch}, data) => {
  return webchatSchedult.updateProcess(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/* 删除流程 start */
/**
 * 删除在线咨询流程节点
 * @param
 * @returns {*}
 */
export const delProcess = ({commit, state, rootState, dispatch}, data) => {
  return webchatSchedult.delProcess(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
/* 在线咨询流程生效 start */
/**
 * 在线咨询流程生效
 * @param
 * @returns {*}
 */
export const reloadProcess = ({commit, state, rootState, dispatch}, data) => {
  return webchatSchedult.reloadProcess(data)
    .then(response => {
      return response
    })
    .catch(() => {
      commit(globalTypes.SET_ERROR, 'message.default_tips')
    })
}
